"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const winston = require("winston");
const stackTrace = require("stack-trace");
const path = require("path");
const fs = require("fs-extra");
const DailyRotateFile = require("winston-daily-rotate-file");
const LOGS_PATH = path.join(__dirname, '../../logs');
fs.ensureDirSync(LOGS_PATH);
function getFileName(name) {
    return path.join(LOGS_PATH, name);
}
const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
        new winston.transports.File({ filename: getFileName('error.log'), level: 'error' }),
        new DailyRotateFile({
            filename: getFileName('combined-%DATE%.log'),
            datePattern: 'YYYY-MM-DD-HH',
            maxSize: '5m'
        })
    ],
    exceptionHandlers: [
        new winston.transports.File({ filename: getFileName('exceptions.log') })
    ]
});
if (JSON.stringify(process.env.NODE_ENV) !== 'production') {
    logger.add(new winston.transports.Console({
        format: winston.format.simple()
    }));
}
const originalErrorLog = logger.error;
logger.error = (...args) => {
    const cellSite = stackTrace.get()[1];
    const extraInfo = args[1] ? args[1] : {};
    return originalErrorLog.apply(logger, [args[0] + '\n', Object.assign({ filePath: cellSite.getFileName(), lineNumber: cellSite.getLineNumber() }, extraInfo)]);
};
exports.default = logger;
